//201902104003邵潇漩
package bysj.service;

import bysj.dao.DegreeDao;
import bysj.domain.Degree;
import util.Condition;
import util.JdbcHelper;
import util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

public final class DegreeService {
    private static DegreeDao degreeDao = DegreeDao.getInstance();
    private static DegreeService degreeService =new DegreeService();
    private DegreeService(){}

    public static DegreeService getInstance(){
        return degreeService;
    }

    public Collection<Degree> findAll(List<Condition> conditionList, Pagination pagination) throws SQLException {
        //获得连接以便完成可能的事务操作
        Connection connection = JdbcHelper.getConn();
        Collection<Degree> degrees = degreeDao.findAll(connection,conditionList,pagination);
        JdbcHelper.close(connection);
        return degrees;
    }

    public Degree find(Integer id) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        Degree degree=degreeDao.find(connection,id);
        JdbcHelper.close(connection);
        return degree;
    }

    public boolean update(Degree degree) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        boolean degree_update=degreeDao.update(connection,degree);
        JdbcHelper.close(connection);
        return degree_update;
    }

    public boolean add(Degree degree) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        boolean degree_add=degreeDao.add(connection,degree);
        JdbcHelper.close(connection);
        return degree_add;
    }

    public boolean delete(Integer id) throws SQLException {
        Degree degree = this.find(id);
        return this.delete(degree);
    }

    public boolean delete(Degree degree) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        boolean degree_del=degreeDao.delete(connection,degree);
        JdbcHelper.close(connection);
        return degree_del;
    }
}

